package net.zjitc.bao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;
import net.zjitc.bao.book;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 毛若颖
 * @date 2025/11/5 11:12
 */

 @Controller
 public class BookController
{    @Autowired
  book book;
    @Autowired
     private Environment env;
    @GetMapping("/book")
    public String book(){
        return book.toString();
    }
     @GetMapping ("/books")
     public ModelAndView books () {
         List<book> books = new ArrayList<>();
         book b1 = new book ();
         b1.setId (1);
         b1.setAuthor ("罗贯中");
         b1.setName ("三国演义");
         book b2 = new book ();
         b2.setId (2);
         b2.setAuthor ("曹雪芹");
         b2.setName ("红楼梦");
         books.add (b1);
         books.add (b2);
         ModelAndView mv = new ModelAndView ();
         mv.addObject ("books", books);
         mv.setViewName ("books");
         return mv;
     }
     @GetMapping("test-config")
    public String testConfig(){
         return "配置文件中的book.name"+env.getProperty("book.name");

     }
 }